package shark.picture.controller;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import shark.picture.common.BaseResponse;
import shark.picture.common.ResultUtils;

import java.math.BigDecimal;

/**
 * @author jianxin.wei
 * @description
 * @date 2025/7/2 14:16
 */
@RestController
@RequestMapping("newTest")
public class NewTestController {
    @PostMapping("test")
    public BaseResponse<String> test(@RequestBody JSONObject param) {
        JSONArray jsonArray = param.getJSONArray("tbElec");
        BigDecimal total = BigDecimal.ZERO;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            String power = jsonObject.getStr("power");
            total = total.add(new BigDecimal(power));
            System.out.println(StrUtil.format("{}  total : {}  power : {} ",i , total ,power));
        }
        return ResultUtils.success(total.toString());
    }

}
